package com.pekall.market.download;

import com.pekall.market.bean.AppListInfo;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Response;

/**
 * 静默安装回调监听
 * 
 */
public class DownloadInterceptor implements Interceptor {

    private DownloadProgressListener listener;
    AppListInfo.ContentBean mBean;

    public DownloadInterceptor(DownloadProgressListener listener,AppListInfo.ContentBean bean) {
        this.listener = listener;
        this.mBean = bean;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Response originalResponse = chain.proceed(chain.request());
        mBean.setMd5(originalResponse.header("md5"));
        return originalResponse.newBuilder()
                .body(new DownloadResponseBody(originalResponse.body(), listener))
                .build();
    }
}
